package com.rn.gypsophila.dsalg.arrary;

/**
 * 题目：最大连续1的个数。给定一个二进制数组 nums ， 计算其中最大连续 1 的个数。
 * 链接：<a href="https://leetcode.cn/leetbook/read/array-and-string/cd71t/">...</a>
 *
 * @author 然诺
 * @since 2023/5/4
 */
public class FindMaxConsecutiveOnes {

    public static int findMaxConsecutiveOnes(int[] nums) {
        int max = 0;
        int temp = 0;
        int left = 0;
        while (left < nums.length) {
            if (nums[left] == 1) {
                temp++;
            } else {
                temp = 0;
            }
            max = Math.max(max, temp);
            left++;
        }
        return max;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1, 1, 0, 1, 1, 1};
        System.out.println(findMaxConsecutiveOnes(nums));
    }

}
